/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uoc.tdp.pac3.client.gui.model;

import edu.uoc.tdp.pac3.bo.IIncidenciaBO;
import edu.uoc.tdp.pac3.bo.impl.IncidenciaBO;
import edu.uoc.tdp.pac3.domain.RequestType;
import edu.uoc.tdp.pac3.to.HistoricIncidenciaTO;
import java.rmi.RemoteException;
import java.util.List;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 * Implementacio de TableModel per poder treure el historic en una taula.
 * @author Gerard
 */
public class HistoricIncidenciaTableModel implements TableModel {

    private List<HistoricIncidenciaTO> items;
    private int columnCount;
    private IIncidenciaBO bo;

    public HistoricIncidenciaTableModel(RequestType requestType) throws RemoteException {
            this.bo = new IncidenciaBO();
            items = bo.getHistorics(requestType);
    }
    
    public int getRowCount() {
        int i = 0;
        if(items != null && items.size() > 0){
            i = items.size();
        }
        return i;
    }

    public int getColumnCount() {
        return 5;
    }

    public String getColumnName(int i) {
        switch(i){
            case 0:
                return "request_id";
            case 1:
                return "description";
            case 2:
                return "user_id";
            case 3:
                return "request_type";
            case 4:
                return "notes";
            default:
                return null;
        }
    }

    public Class<?> getColumnClass(int i) {
        switch(i){
            case 0:
                return Integer.class;
            case 1:
                return String.class;
            case 2:
                return Integer.class;
            case 3:
                return RequestType.class;
            case 4:
                return String.class;
            default:
                return null;
        }
    }

    public boolean isCellEditable(int i, int i1) {
        return false;
    }

    public Object getValueAt(int row, int column) {
        HistoricIncidenciaTO item = items.get(row);
        switch(column){
            case 0:
                return item.getRequest().getId();
            case 1:
                return item.getRequest().getDescription();
            case 2:
                return item.getRequest().getUserId();
            case 3:
                return item.getRequest().getRequestType();
            case 4:
                return item.getNotesString();
            
                default:
                    return null;
        }
    }

    public void setValueAt(Object object, int row, int column) {
        HistoricIncidenciaTO item = items.get(row);
        switch(column){
            case 0:
                 item.getRequest().setId((Integer)object);
            case 1:
                item.getRequest().setDescription((String)object);
            case 2:
                item.getRequest().setUserId((Integer)object);
            case 3:
                item.getRequest().setRequestType((RequestType)object);
            case 4:
                item.setNotesString((String)object);
        }
        
    }

    public void addTableModelListener(TableModelListener tl) {
      
    }

    public void removeTableModelListener(TableModelListener tl) {
      
    }
    
}
